{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h1 align=\"center\"> Time Series Data Basics with Pandas Part 3: Price Variation from Pandas groupby </h1>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This code demonstrates how to  \n",
    "\n",
    "**if this tutorial doesn't cover what you are looking for, please leave a comment below the youtube video and I will try to cover what you are interested in.**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<b> Part 1 </b>: Sampling, Rolling Mean (Smoothing), Linear Regression, Filtering, Join, plotting of a Time Series Pandas DataFrame <br>\n",
    "https://www.youtube.com/watch?v=OwnaUVt6VVE"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<b> Part 2 </b>: Price Variation from Pandas GroupBy <br>\n",
    "https://www.youtube.com/watch?v=1S5UKLqe-gg"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3 align='Left'> Importing Libraries</h3>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import pandas_datareader.data as web\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3 align='Left'> Getting Data and Viewing with Pandas </h3>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2009-03-16</th>\n",
       "      <td>162.83</td>\n",
       "      <td>164.70</td>\n",
       "      <td>159.14</td>\n",
       "      <td>159.69</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2009-03-17</th>\n",
       "      <td>159.93</td>\n",
       "      <td>167.50</td>\n",
       "      <td>159.39</td>\n",
       "      <td>167.50</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2009-03-18</th>\n",
       "      <td>167.24</td>\n",
       "      <td>169.83</td>\n",
       "      <td>163.86</td>\n",
       "      <td>166.38</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2009-03-19</th>\n",
       "      <td>165.67</td>\n",
       "      <td>167.83</td>\n",
       "      <td>163.53</td>\n",
       "      <td>164.81</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2009-03-20</th>\n",
       "      <td>164.98</td>\n",
       "      <td>166.33</td>\n",
       "      <td>163.01</td>\n",
       "      <td>164.91</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              Open    High     Low   Close  Volume\n",
       "Date                                              \n",
       "2009-03-16  162.83  164.70  159.14  159.69     NaN\n",
       "2009-03-17  159.93  167.50  159.39  167.50     NaN\n",
       "2009-03-18  167.24  169.83  163.86  166.38     NaN\n",
       "2009-03-19  165.67  167.83  163.53  164.81     NaN\n",
       "2009-03-20  164.98  166.33  163.01  164.91     NaN"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# https://pandas-datareader.readthedocs.io/en/latest/remote_data.html\n",
    "google = web.DataReader('GOOG', data_source = 'google', start = '3/14/2009', end = '4/14/2016')\n",
    "google.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3 align='Left'> Getting Data and Viewing with Pandas </h3>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2009-03-31</th>\n",
       "      <td>169.330000</td>\n",
       "      <td>172.208333</td>\n",
       "      <td>166.874167</td>\n",
       "      <td>169.822500</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2009-04-30</th>\n",
       "      <td>187.539524</td>\n",
       "      <td>190.871905</td>\n",
       "      <td>185.564286</td>\n",
       "      <td>188.649048</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2009-05-31</th>\n",
       "      <td>199.750000</td>\n",
       "      <td>201.946500</td>\n",
       "      <td>197.298500</td>\n",
       "      <td>199.814000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2009-06-30</th>\n",
       "      <td>211.566818</td>\n",
       "      <td>213.439091</td>\n",
       "      <td>209.372273</td>\n",
       "      <td>211.680909</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2009-07-31</th>\n",
       "      <td>212.957273</td>\n",
       "      <td>215.438182</td>\n",
       "      <td>210.859545</td>\n",
       "      <td>213.432727</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  Open        High         Low       Close  Volume\n",
       "Date                                                              \n",
       "2009-03-31  169.330000  172.208333  166.874167  169.822500     NaN\n",
       "2009-04-30  187.539524  190.871905  185.564286  188.649048     NaN\n",
       "2009-05-31  199.750000  201.946500  197.298500  199.814000     NaN\n",
       "2009-06-30  211.566818  213.439091  209.372273  211.680909     NaN\n",
       "2009-07-31  212.957273  215.438182  210.859545  213.432727     NaN"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "google_date = google.groupby(pd.TimeGrouper(freq='M')).mean()\n",
    "google_date.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Date</th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2009-03-31</td>\n",
       "      <td>169.330000</td>\n",
       "      <td>172.208333</td>\n",
       "      <td>166.874167</td>\n",
       "      <td>169.822500</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2009-04-30</td>\n",
       "      <td>187.539524</td>\n",
       "      <td>190.871905</td>\n",
       "      <td>185.564286</td>\n",
       "      <td>188.649048</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2009-05-31</td>\n",
       "      <td>199.750000</td>\n",
       "      <td>201.946500</td>\n",
       "      <td>197.298500</td>\n",
       "      <td>199.814000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2009-06-30</td>\n",
       "      <td>211.566818</td>\n",
       "      <td>213.439091</td>\n",
       "      <td>209.372273</td>\n",
       "      <td>211.680909</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2009-07-31</td>\n",
       "      <td>212.957273</td>\n",
       "      <td>215.438182</td>\n",
       "      <td>210.859545</td>\n",
       "      <td>213.432727</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        Date        Open        High         Low       Close  Volume\n",
       "0 2009-03-31  169.330000  172.208333  166.874167  169.822500     NaN\n",
       "1 2009-04-30  187.539524  190.871905  185.564286  188.649048     NaN\n",
       "2 2009-05-31  199.750000  201.946500  197.298500  199.814000     NaN\n",
       "3 2009-06-30  211.566818  213.439091  209.372273  211.680909     NaN\n",
       "4 2009-07-31  212.957273  215.438182  210.859545  213.432727     NaN"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "google_date = google_date.reset_index()\n",
    "google_date.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Date</th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>2014-03-31</td>\n",
       "      <td>594.312381</td>\n",
       "      <td>597.200000</td>\n",
       "      <td>587.170476</td>\n",
       "      <td>590.631905</td>\n",
       "      <td>2.675957e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61</th>\n",
       "      <td>2014-04-30</td>\n",
       "      <td>528.889524</td>\n",
       "      <td>548.008095</td>\n",
       "      <td>532.993333</td>\n",
       "      <td>540.014286</td>\n",
       "      <td>3.397846e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>2014-05-31</td>\n",
       "      <td>533.136190</td>\n",
       "      <td>537.571429</td>\n",
       "      <td>528.415714</td>\n",
       "      <td>534.053333</td>\n",
       "      <td>1.740365e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>2014-06-30</td>\n",
       "      <td>557.843810</td>\n",
       "      <td>561.529048</td>\n",
       "      <td>552.762857</td>\n",
       "      <td>558.430476</td>\n",
       "      <td>1.806047e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>2014-07-31</td>\n",
       "      <td>584.146818</td>\n",
       "      <td>587.762727</td>\n",
       "      <td>579.377273</td>\n",
       "      <td>584.015909</td>\n",
       "      <td>1.570525e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>2014-08-31</td>\n",
       "      <td>574.153810</td>\n",
       "      <td>577.222381</td>\n",
       "      <td>569.963810</td>\n",
       "      <td>573.600476</td>\n",
       "      <td>1.315643e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>2014-09-30</td>\n",
       "      <td>581.562857</td>\n",
       "      <td>585.084762</td>\n",
       "      <td>577.776667</td>\n",
       "      <td>581.889048</td>\n",
       "      <td>1.593645e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>2014-10-31</td>\n",
       "      <td>548.336087</td>\n",
       "      <td>553.207826</td>\n",
       "      <td>541.793478</td>\n",
       "      <td>547.030000</td>\n",
       "      <td>2.264480e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>68</th>\n",
       "      <td>2014-11-30</td>\n",
       "      <td>544.258947</td>\n",
       "      <td>546.484737</td>\n",
       "      <td>539.902632</td>\n",
       "      <td>542.977895</td>\n",
       "      <td>1.497144e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>69</th>\n",
       "      <td>2014-12-31</td>\n",
       "      <td>524.969091</td>\n",
       "      <td>529.458182</td>\n",
       "      <td>520.442273</td>\n",
       "      <td>524.626818</td>\n",
       "      <td>2.081665e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>2015-01-31</td>\n",
       "      <td>513.224500</td>\n",
       "      <td>517.870500</td>\n",
       "      <td>506.693000</td>\n",
       "      <td>512.418000</td>\n",
       "      <td>2.504921e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>2015-02-28</td>\n",
       "      <td>535.915789</td>\n",
       "      <td>541.594737</td>\n",
       "      <td>532.400526</td>\n",
       "      <td>537.992105</td>\n",
       "      <td>1.710954e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>2015-03-31</td>\n",
       "      <td>560.359545</td>\n",
       "      <td>564.172273</td>\n",
       "      <td>555.578182</td>\n",
       "      <td>559.715909</td>\n",
       "      <td>1.751945e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>2015-04-30</td>\n",
       "      <td>541.159524</td>\n",
       "      <td>545.041429</td>\n",
       "      <td>536.298571</td>\n",
       "      <td>540.497619</td>\n",
       "      <td>2.013497e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>2015-05-31</td>\n",
       "      <td>535.470500</td>\n",
       "      <td>539.167000</td>\n",
       "      <td>531.406500</td>\n",
       "      <td>535.239000</td>\n",
       "      <td>1.593339e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>2015-06-30</td>\n",
       "      <td>533.834545</td>\n",
       "      <td>536.315455</td>\n",
       "      <td>530.060909</td>\n",
       "      <td>532.915909</td>\n",
       "      <td>1.561024e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>2015-07-31</td>\n",
       "      <td>588.200455</td>\n",
       "      <td>596.199091</td>\n",
       "      <td>582.965455</td>\n",
       "      <td>590.093636</td>\n",
       "      <td>2.878157e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>2015-08-31</td>\n",
       "      <td>639.427143</td>\n",
       "      <td>646.968571</td>\n",
       "      <td>629.205714</td>\n",
       "      <td>636.838095</td>\n",
       "      <td>2.558164e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>2015-09-30</td>\n",
       "      <td>618.796190</td>\n",
       "      <td>624.522857</td>\n",
       "      <td>611.291429</td>\n",
       "      <td>617.934762</td>\n",
       "      <td>2.283404e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>2015-10-31</td>\n",
       "      <td>662.285909</td>\n",
       "      <td>669.261818</td>\n",
       "      <td>655.553636</td>\n",
       "      <td>663.592727</td>\n",
       "      <td>2.225862e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>2015-11-30</td>\n",
       "      <td>733.636000</td>\n",
       "      <td>740.525000</td>\n",
       "      <td>728.927000</td>\n",
       "      <td>735.388500</td>\n",
       "      <td>1.680540e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>2015-12-31</td>\n",
       "      <td>756.099545</td>\n",
       "      <td>762.109545</td>\n",
       "      <td>747.239545</td>\n",
       "      <td>755.354545</td>\n",
       "      <td>1.957391e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>2016-01-31</td>\n",
       "      <td>719.503158</td>\n",
       "      <td>728.158421</td>\n",
       "      <td>708.215789</td>\n",
       "      <td>718.495789</td>\n",
       "      <td>2.436567e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>2016-02-29</td>\n",
       "      <td>706.394500</td>\n",
       "      <td>714.834000</td>\n",
       "      <td>695.218000</td>\n",
       "      <td>702.689000</td>\n",
       "      <td>3.177772e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>2016-03-31</td>\n",
       "      <td>725.265455</td>\n",
       "      <td>731.451818</td>\n",
       "      <td>720.084545</td>\n",
       "      <td>727.056818</td>\n",
       "      <td>1.881903e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>85</th>\n",
       "      <td>2016-04-30</td>\n",
       "      <td>743.596000</td>\n",
       "      <td>748.515000</td>\n",
       "      <td>738.621000</td>\n",
       "      <td>744.223000</td>\n",
       "      <td>1.300156e+06</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         Date        Open        High         Low       Close        Volume\n",
       "60 2014-03-31  594.312381  597.200000  587.170476  590.631905  2.675957e+06\n",
       "61 2014-04-30  528.889524  548.008095  532.993333  540.014286  3.397846e+06\n",
       "62 2014-05-31  533.136190  537.571429  528.415714  534.053333  1.740365e+06\n",
       "63 2014-06-30  557.843810  561.529048  552.762857  558.430476  1.806047e+06\n",
       "64 2014-07-31  584.146818  587.762727  579.377273  584.015909  1.570525e+06\n",
       "65 2014-08-31  574.153810  577.222381  569.963810  573.600476  1.315643e+06\n",
       "66 2014-09-30  581.562857  585.084762  577.776667  581.889048  1.593645e+06\n",
       "67 2014-10-31  548.336087  553.207826  541.793478  547.030000  2.264480e+06\n",
       "68 2014-11-30  544.258947  546.484737  539.902632  542.977895  1.497144e+06\n",
       "69 2014-12-31  524.969091  529.458182  520.442273  524.626818  2.081665e+06\n",
       "70 2015-01-31  513.224500  517.870500  506.693000  512.418000  2.504921e+06\n",
       "71 2015-02-28  535.915789  541.594737  532.400526  537.992105  1.710954e+06\n",
       "72 2015-03-31  560.359545  564.172273  555.578182  559.715909  1.751945e+06\n",
       "73 2015-04-30  541.159524  545.041429  536.298571  540.497619  2.013497e+06\n",
       "74 2015-05-31  535.470500  539.167000  531.406500  535.239000  1.593339e+06\n",
       "75 2015-06-30  533.834545  536.315455  530.060909  532.915909  1.561024e+06\n",
       "76 2015-07-31  588.200455  596.199091  582.965455  590.093636  2.878157e+06\n",
       "77 2015-08-31  639.427143  646.968571  629.205714  636.838095  2.558164e+06\n",
       "78 2015-09-30  618.796190  624.522857  611.291429  617.934762  2.283404e+06\n",
       "79 2015-10-31  662.285909  669.261818  655.553636  663.592727  2.225862e+06\n",
       "80 2015-11-30  733.636000  740.525000  728.927000  735.388500  1.680540e+06\n",
       "81 2015-12-31  756.099545  762.109545  747.239545  755.354545  1.957391e+06\n",
       "82 2016-01-31  719.503158  728.158421  708.215789  718.495789  2.436567e+06\n",
       "83 2016-02-29  706.394500  714.834000  695.218000  702.689000  3.177772e+06\n",
       "84 2016-03-31  725.265455  731.451818  720.084545  727.056818  1.881903e+06\n",
       "85 2016-04-30  743.596000  748.515000  738.621000  744.223000  1.300156e+06"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame(data = google_date.dropna())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "MOW\n"
     ]
    }
   ],
   "source": [
    "from IPython.html import widgets\n",
    "from IPython.display import display\n",
    "\n",
    "geo={'USA':['CHI','NYC'],'Russia':['MOW','LED']}\n",
    "\n",
    "def print_city(city):\n",
    "    print city\n",
    "\n",
    "def select_city(country):\n",
    "    cityW.options = geo[country]\n",
    "\n",
    "\n",
    "scW = widgets.Select(options=geo.keys())\n",
    "init = scW.value\n",
    "cityW = widgets.Select(options=geo[init])\n",
    "j = widgets.interactive(print_city, city=cityW)\n",
    "i = widgets.interactive(select_city, country=scW)\n",
    "display(i)\n",
    "display(j)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "u'oranges'"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from __future__ import print_function\n",
    "from ipywidgets import interact, interactive, fixed\n",
    "import ipywidgets as widgets\n",
    "def f(x):\n",
    "    return x\n",
    "\n",
    "interact(f, x=('apples','oranges'));"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
